﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using SmartCity.Shared;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace CommonManagement
{
    /// <summary>
    /// 积分等级应用服务类
    /// </summary>
    public class LevelAppService : ApplicationService, ILevelAppService
    {
        private readonly IRepository<Level, int> _levelRepository;

        public LevelAppService(
            IRepository<Level, int> levelRepository)
        {
            _levelRepository = levelRepository;
        }

        // 列表
        public async Task<ListResponse<LevelDto>> ListAsync()
        {
            // 查询
            var levels = await _levelRepository
                .OrderBy(m => m.Score)
                .ToListAsync();
            // entity转dto
            var dtos = ObjectMapper.Map<List<Level>, List<LevelDto>>(levels);
            // 返回结果
            return ListResponse<LevelDto>.Successful(dtos.Count, dtos);
        }
    }
}